﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Structura.Silverlight.Infrastructure.Commanding;
using MusicStore.Silverlight.ViewModels;
using System.Windows.Navigation;
using Castle.Core.Logging;

namespace MusicStore.Silverlight.Commands
{
    public class NavigateToAlbumCommand : BaseCommand
    {
        public NavigateToAlbumCommand(ISearchViewModel viewModel)
        {
            _viewModel = viewModel;
        }

        private ISearchViewModel _viewModel;

        public ILogger Logger { get; set; }

        private Page page { get { return _viewModel.View as Page; } }

        protected override bool CanExecuteImpl(object parameter)
        {
            return !_viewModel.IsBusy;
        }

        public override void Execute(object parameter)
        {
            int id = 0;
            if (parameter != null)
                id = (int)parameter;
            NavigateToAlbum(id);
        }

        private void NavigateToAlbum(int id)
        {
            Logger.Info(string.Format("UI - Navigating to Album({0})", id));

            page.NavigationService.Navigate(new Uri(string.Format("/Album/{0}", id), UriKind.Relative));
        }
    }
}
